package com.study.exam.controller;

import com.study.exam.pojo.User;
import com.study.exam.service.UserService;
import com.study.exam.vo.UserUpdateVO;
import com.study.exam.vo.UserVO;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@Api(value = "用户数据测试",tags = "用户数据接口API")
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    public Map<String, Object> selectNull() {
        return userService.selectUsers(null);
    }
    @GetMapping("/selectUsers")
    @ApiOperation(value = "用户查询列表接口 get",notes = "用户查询列表接口 get",httpMethod = "GET", response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public Map<String, Object> selectUsers(UserVO userVO) {
        return userService.selectUsers(userVO);
    }

    @PostMapping("/insert")
    public Map<String, Object> insert(@RequestBody UserVO userVO) {
        return userService.insert(userVO);
    }

    @PostMapping("/login")
    public Map<String, Object> login(@RequestBody UserVO userVO) {
        return userService.login(userVO);
    }

    @PostMapping("/deleteById")
    public Map<String, Object> deleteById(@RequestParam Integer id) {
        return userService.deleteById(id);
    }

    @PostMapping("/updateById")
    public Map<String, Object> updateById(@RequestBody UserUpdateVO userUpdateVO) {
        return userService.updateById(userUpdateVO);
    }

    @PostMapping("/selectUsersPost")
    @ApiOperation(value = "用户查询列表接口",notes = "用户查询列表接口 POST",httpMethod = "POST", response = String.class)
    public Map<String, Object> selectUsersPost(@RequestBody @ApiParam(name = "user",value = "用户名和密码", required = true) User user) {
        System.out.println("user.getUsername()=" + user.getUsername());
        System.out.println("user.getPassword()=" + user.getPassword());
        return userService.selectUsers(null);
    }

    @PostMapping("/testPost")
    @ApiOperation(value = "用户查询列表接口 post",notes = "用户查询列表接口 post",httpMethod = "POST", response = String.class)
    public Map<String, Object> testPost() {
        return userService.selectUsers(null);
    }

    @PutMapping("/testPut")
    public Map<String, Object> testPut() {
        return userService.selectUsers(null);
    }

    @DeleteMapping("/testDelete")
    public Map<String, Object> testDelete() {
        return userService.selectUsers(null);
    }


    @RequestMapping("/testRequest")
    public Map<String, Object> testRequest() {
        return userService.selectUsers(null);
    }

}
